<?php
     
     header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header ("Cache-Control: no-cache, must-revalidate");
     header ("Pragma: no-cache");
     
     header("content-type: application/x-javascript; charset=tis-620");
    include_once('connection/connection.php');
     $data=$_GET['data'];
     $val=$_GET['val'];
	 
	 if($data=='district')
	 {
        // echo "<select name='district' id='district' class='txt' onChange=\"changeBlock('block',this.value); change_factor('factor',this.value); changeTehsil('tehsil',this.value)\">\n";
		echo "<select name='district' id='district' class='txt' onChange=\"changeBlock('block',this.value)\">\n";
          echo "<option value='0'>==== District ====</option>\n";
          $result=mysql_query("select DISTINCT district_id, district_name from tbl_lookup_location order by district_name");
          while(list($id, $name)=mysql_fetch_array($result))
		  {
               echo "<option value=\"$id\">$name</option> \n" ;
          }    
	 }
	 
	 /*if($data=='factor')
	 {		
         $val2=$val;
         $val = substr($val,0,10); 
		$qr="SELECT population_factor FROM tbl_lookup_pop_factor WHERE district_id = '$val'";
		$res=mysql_query($qr);
		$row=mysql_fetch_array($res);
		$factor=$row['population_factor'];
		?>    
		<input type="hidden"  name="factor1" id="factor1" value="<?php echo $factor;?>" class="txt5" size=20 style="color:#FF0000">
        <?php 
	 }*/
	 
	 if($data=='block')
	 {		
         	echo "<select name='block' class='txt' onChange=\"changePanchayat('panchayat',this.value)\" >\n
         	<option value='0'>=====Block====</option>\n";
         	$val2=$val;
         	$val = substr($val,0,10);                            
         	$result=mysql_query("SELECT DISTINCT block_id, block_name from tbl_lookup_location where district_id='$val' order by block_name");
         	while(list($id, $name)=mysql_fetch_array($result))
		 	{       
             	 echo "<option value=\"$id\">$name</option> \n";
         	}
			echo "</select>";	 	
	 }
	 
	/*if($data=='tehsil')
	{
		 echo "<select name='tehsil' class='txt'>\n
         <option value='0'>=====Tehsil====</option>\n";
		 $result1=mysql_query("SELECT DISTINCT census_subdistrict_code,census_subdistrict_name from tbl_lookup_location where district_id='$val' order by census_subdistrict_name");
		 while(list($id1, $name1)=mysql_fetch_array($result1))
		 {       
              echo "<option value=\"$id1\">$name1</option> \n";
         }	 	
	}*/
	
	 if ($data=='panchayat') 
	 {
		 $val2=$val;
		 $val = substr($val,0,10);
          echo "<select name='panchayat' class='txt' onChange=\"changeVillage('village',this.value)\">\n
          <option value='0'>=Gram panchayat=</option>\n";
          $val2=$val;
		  $val = substr($val,0,10);
          $result=mysql_query("SELECT DISTINCT panchayat_id, panchayat_name from tbl_lookup_location where block_id='$val' order by panchayat_name");
          while(list($id, $name)=mysql_fetch_array($result))
		  {
               echo "<option value=\"$id\">$name</option> \n" ;
          }
	  }
	   
	 if ($data=='village') 
	  {
		 $val2=$val;
		 $val = substr($val,0,10);
        // echo "<select  name='village' class='txt' onChange=\"changeHabit('habit',this.value);changeHabit1('habit1',this.value);changeCensusCode('cvc',this.value);changeFormId(this.form,'form_id',this.value);changePopulation('population_benefited',this.value);changePrePopulation('present_population',this.value)\" >\n";
		 echo "<select  name='village' class='txt' onChange=\"changeHabit1('habit1',this.value)\" >\n";
          echo "<option value='0'>=====Village====</option>\n";
          $val2=$val;
		  $val = substr($val,0,10);
          $result=mysql_query("SELECT DISTINCT village_id, village_name from tbl_lookup_location where panchayat_id='$val' order by village_name");
          while(list($id, $name)=mysql_fetch_array($result))
		  {
               echo "<option value=\"$id\">$name</option> \n" ;
          }
		}
		
		if ($data=='habit1') 
	  	{
		 $val2=$val;
		 $val = substr($val,0,10);
         echo "<select  name='habit1' class='txt'>\n";
          echo "<option value='0'>===Habitation===</option>\n";
          $result=mysql_query("SELECT DISTINCT habitation_code, habitation_name from tbl_lookup_location where village_id='$val' order by habitation_name");
          while(list($id, $name)=mysql_fetch_array($result))
		  {
               echo "<option value=\"$id\">$name</option> \n" ;
          }
		}
		
		/*if ($data =='cvc') 
	  	{
			$val2=$val;
			$val = substr($val,0,10);
		    $result=mysql_query("SELECT DISTINCT census_village_code from tbl_lookup_location where village_id='$val' order by village_name");
         while(list($id1)=mysql_fetch_array($result))
		 { ?>      
              <input type="text" name="cvc" value="<?php echo $id1;?>" readonly class=txt size=20 style="color:#FF0000">
         <?php }
		 }
		 
		 if ($data =='population_benefited') 
	  	{
			$val2=$val;
			$val = substr($val,0,10);
			$qr="SELECT SUM(total_population) AS total_population from tbl_lookup_location where village_id='$val' order by village_name";
			$res=mysql_query($qr);
			$row=mysql_fetch_array($res);
			$id2=$row['total_population'];
		   ?>      
		   <input type="text" name="population_benefited1" id="population_benefited1" value="<?php echo $id2;?>" readonly class="txt5" size="20" style="color:#FF0000">
         <?php 
		 }
		 
		 if ($data =='present_population') 
	  	{
			$val2=$val;
			$val = substr($val,0,10); ?>
         <input type="text" name="present_population1" id="present_population1" value="" readonly class="txt5" size="20" style="color:#FF0000" />
         <?php 
		 }
		 
		 
		if ($data =='form_id') 
	  	{
		 	$val2=$val;
			$val = substr($val,0,10);
			$dist=$_GET['dist'];
			$qid="UPDATE sequence SET id=LAST_INSERT_ID(id+1)";
			$rid = mysql_query($qid);
			$qryId="select id from sequence";
			$recId=mysql_query($qryId);
			$rowId=mysql_fetch_array($recId);
			$id=$rowId['id'];
			$form_id = substr($dist,0,4);
			$form_id = "Q1" . "-" . $form_id . "-"  . $id;
			?>
			<input type="text" style="color:#FF0000" name="form_id" value="<?php echo $form_id; ?>" readonly class=txt size=20>
			<input type="hidden" style="color:#FF0000" name="id" value="<?php echo $id; ?>" readonly class=txt size=20>
		<?php }
		
			
		if ($data=='habit') 
	    {
		 $val2=$val;
		 $val = substr($val,0,10);
		 $q="SELECT DISTINCT habitation_code, habitation_name from tbl_lookup_location where village_id='$val' order by habitation_code";
          $val2=$val;
		  $val = substr($val,0,10);
          $result=mysql_query($q);
		  $num_habit = mysql_num_rows($result);
		  echo"<table>";
		   $i=1;
		  while(list($id, $name)=mysql_fetch_array($result))
		  {
			 ?>
			 <tr>
				<td width="22%" align="center"><font id=habit>
					<input type="text" name="name_habi<?php echo $i;?>" id="name_habi<?php echo $i;?>"value="<?php echo ucwords(strtolower($name));?>" class="txt7" readonly></font>
				</td>
				<td width="15%" align="left"><font id=habit_code>
					<input type="text" name="habi_code<?php echo $i;?>" id="habi_code<?php echo $i;?>"value="<?php echo $id;?>" class="txt7" readonly></font>
				</td>
				<td align="center" width="4%"><input type="text" name="type_habit<?php echo $i;?>" id="type_habit<?php echo $i;?>" value="<?php if($i==1){ echo "MH"; } else { echo "OH"; } ?>" size="2" class="txt_1" readonly/></td>
				<td width="18%" align="center">
					<input type="radio" name="status<?php echo $i;?>" id="status<?php echo $i;?>" value="Existing" checked onClick="setEnable(this.value,<?php echo $i; ?>)"><font style="font-size: 8.5pt" face="Verdana" color="#000000">E</font>
					<input type="radio" name="status<?php echo $i;?>" id="status<?php echo $i;?>" onClick="setReadOnly(this.value,<?php echo $i; ?>)"value="NON TRACABLE"><font style="font-size: 8.5pt" face="Verdana" color="#000000">NT</font></p>
				</td>
			</tr>
			<?php
			   $i++;
          }  
		  echo "<input type='hidden' name='habcount' id='habcount' value=".$num_habit."></table>"; 
     } */
?>